package club.haomoon.boss.controller;

import club.haomoon.boss.aop.Log;
import club.haomoon.boss.validate.article.ArtCateCreateValidate;
import club.haomoon.boss.validate.article.ArtCateSearchValidate;
import club.haomoon.boss.validate.article.ArtCateUpdateValidate;
import club.haomoon.boss.validate.base.IdValidate;
import club.haomoon.boss.validate.base.PageValidate;
import club.haomoon.boss.vo.article.ArticleCategoryVo;
import club.haomoon.boss.service.IArtCateService;
import club.haomoon.core.aop.FreeValidator;
import club.haomoon.core.common.AjaxResult;
import club.haomoon.core.common.PageResult;
import club.haomoon.core.validator.annotation.IDMust;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping({"/adminapi/article/articleCate", "/adminapi/article.articleCate"})
@Tag(name =  "文章分类管理")
public class ArtCateController {

    @Resource
    IArtCateService iArtCateService;

    @FreeValidator
    @GetMapping("/all")
    @Operation(summary="所有分类")
    public AjaxResult<List<ArticleCategoryVo>> all() {
        List<ArticleCategoryVo> list = iArtCateService.all();
        return AjaxResult.success(list);
    }

    @GetMapping("/lists")
    @Operation(summary="分类列表")
    public AjaxResult<PageResult<ArticleCategoryVo>> list(@Validated PageValidate pageValidate,
                                                          @Validated ArtCateSearchValidate searchValidate) {
        PageResult<ArticleCategoryVo> list = iArtCateService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail")
    @Operation(summary="分类详情")
    public AjaxResult<ArticleCategoryVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        ArticleCategoryVo vo = iArtCateService.detail(id);
        return AjaxResult.success(vo);
    }

    @Log(title = "文章分类新增")
    @PostMapping("/add")
    @Operation(summary="分类新增")
    public AjaxResult<Object> add(@Validated @RequestBody ArtCateCreateValidate createValidate) {
        iArtCateService.add(createValidate);
        return AjaxResult.success();
    }

    @Log(title = "文章分类编辑")
    @PostMapping("/edit")
    @Operation(summary="分类编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody ArtCateUpdateValidate updateValidate) {
        iArtCateService.edit(updateValidate);
        return AjaxResult.success();
    }

    @Log(title = "文章分类删除")
    @PostMapping("/delete")
    @Operation(summary="分类删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iArtCateService.del(idValidate.getId());
        return AjaxResult.success();
    }

    @Log(title = "文章分类状态")
    @PostMapping("/updateStatus")
    @Operation(summary="分类状态")
    public AjaxResult<Object> change(@Validated @RequestBody IdValidate idValidate) {
        iArtCateService.change(idValidate.getId());
        return AjaxResult.success();
    }

}
